package pp.strategy.task;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pp.IProjectJobStrategy;
import pp.strategy.worktime.HandWorkTimeStrategy;

public enum TaskStrategyEnum {
    AUTO(AutoTaskStrategy.class),
    HAND(HandTaskStrategy.class),
    ;

    private static final Logger logger = LoggerFactory.getLogger(TaskStrategyEnum.class);
    private Class<? extends IProjectJobStrategy> aClass;

    TaskStrategyEnum(Class<? extends IProjectJobStrategy> aClass) {
        this.aClass = aClass;
    }

    public static IProjectJobStrategy newStrategy(String type) {
        for (TaskStrategyEnum value : values()) {
            if (value.name().equalsIgnoreCase(type)) {
                try {
                    logger.info("工作任务选择使用[{}]模式", type);
                    return value.aClass.newInstance();
                } catch (InstantiationException e) {
                    throw new RuntimeException(e);
                } catch (IllegalAccessException e) {
                    throw new RuntimeException(e);
                }
            }
        }
        return new HandTaskStrategy();
    }
}
